package com.kfm.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kfm.hotel.domain.SysMenu;
import com.kfm.hotel.service.SysMenuService;
import com.kfm.hotel.mapper.SysMenuMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【sys_menu(菜单表)】的数据库操作Service实现
* @createDate 2023-06-16 14:26:43
*/
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
    implements SysMenuService{

    @Override
    public List<SysMenu> getAllMenusByTree() {
        //查询一级菜单
        QueryWrapper<SysMenu> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id",0);
        //升序排序
        wrapper.orderByAsc("order_num");
        List<SysMenu> menus = list(wrapper);
        //查询子菜单
        for (SysMenu menu:menus) {
            QueryWrapper<SysMenu> wrapper1 = new QueryWrapper<>();
            wrapper1.eq("parent_id",menu.getId());
            //升序排序
            wrapper1.orderByAsc("order_num");
            List<SysMenu> list1 = list(wrapper1);
            menu.setChildren(list1);

        }
        return menus;
    }
}




